import type { FileParams } from 'ofetch'

const appApi = {
    /**
     * AI模型配置
     *
     * @returns {Promise<AppAiModelsResponse>}
     * @author zero
     */
    models(): Promise<AppAiModelsResponse> {
        return $request.get<AppAiModelsResponse>({
            url: '/index/models'
        })
    },

    /**
     * 系统基础配置
     *
     * @returns {Promise<AppConfigResponse>}
     * @author zero
     */
    config(): Promise<AppConfigResponse> {
        return $request.get<AppConfigResponse>({
            url: '/index/config'
        })
    },

    /**
     * 获取装修数据
     *
     * @param {number} scene 场景值: [100=主页, 200=桌面]
     * @returns {Promise<AppDiyResponse>}
     * @author zero
     */
    diy(scene: number): Promise<AppDiyResponse> {
        return $request.get<AppDiyResponse>({
            url: '/index/diy',
            params: {
                scene
            }
        })
    },

    /**
     * 获取政策协议
     *
     * @param type
     * @returns {Promise<AppPolicyResponse>}
     * @author zero
     */
    policy(type: number): Promise<AppPolicyResponse> {
        return $request.get<AppPolicyResponse>({
            url: '/index/policy',
            params: {
                type
            }
        })
    },

    /**
     * 系统消息监听
     *
     * @returns {Promise<AppMonitorResponse>}
     * @author zero
     */
    monitor(): Promise<AppMonitorResponse> {
        return $request.get<any>({
            url: '/index/monitor'
        })
    },

    /**
     * 文件上传
     *
     * @param {FileParams} params 上传参数
     * @param {File} params.file 要上传的文件对象
     * @param {string} [params.name] 文件名称(可选)
     * @param {any} [params.data] 附加数据(可选)
     * @returns {Promise<AppUploadResponse>}
     * @author zero
     */
    upload(params: FileParams): Promise<AppUploadResponse> {
        return $request.uploadFile<AppUploadResponse>({
            url: '/upload/files'
        }, {
            file: params.file,
            name: params?.name,
            data: params?.data
        })
    },

    /**
     * 发送短信验证码
     *
     * @param params
     * @param {number} params.scene 发送场景
     * @param {string} params.mobile 手机号码
     * @returns {Promise<any>}
     * @author zero
     */
    sendSms(params: { scene: number, mobile: string }): Promise<any> {
        return $request.post({
            url: '/index/send_sms',
            params: {
                scene: params.scene,
                mobile: params.mobile
            }
        })
    },

    /**
     * 发送邮箱验证码
     *
     * @param params
     * @param {number} params.scene 发送场景
     * @param {string} params.email 邮箱地址
     * @returns {Promise<any>}
     * @author zero
     */
    sendEmail(params: {
        scene: number;
        email: string;
    }): Promise<any> {
        return $request.post({
            url: '/index/send_email',
            params: {
                scene: params.scene,
                email: params.email
            }
        })
    }
}

export default appApi
